
function PRED_var = VAR_fore(X,p,h);

[T N] = size(X);

Z = ones(T-p,1);

for j = 1:p;

    Z = [Z X(p+1-j:end-j,:) ];

end;

coeff=(inv(Z'*Z)*Z'*X(p+1:end,:))';

comp = [coeff(:,2:end); [kron(eye(N),eye(p-1)) zeros(N*(p-1),N)]];

C = [coeff(:,1); zeros(N*(p-1),1)];

cons=zeros(size(C,1),1);

for hh = 1:h
    cons = cons+comp^(hh-1)*C;
    pred(:,hh) = cons + comp^hh*[X(end,:)'; Z(end,2:end-N)'];
end

PRED_var =pred(1:N,:);